package surfing.chatting.union;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

public class IpQuerry {
	public Map<String, String> querry() {
		try {
			URL url = new URL("https://whois.pconline.com.cn/ipJson.jsp?json=true");
			URLConnection cnn = url.openConnection();
			HttpURLConnection hcon = (HttpURLConnection) cnn;
			hcon.setDoInput(true);
			BufferedReader in;
			in = new BufferedReader(new InputStreamReader(hcon.getInputStream()));
			StringBuffer responseStr = new StringBuffer();
			String line;
			while ((line = in.readLine()) != null) {
				responseStr.append(line);
			}
			JSONObject object = new JSONObject(new String(responseStr));
			Map<String, String> map = new HashMap<String, String>();
			;
			map.put("ip",object.getString("ip"));
			map.put("addr",object.getString("addr"));
			return map;

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;

	}
}
